package com.lqs.dataservice.Service;

import com.lqs.dataservice.constants.MessageConstants;
import com.lqs.dataservice.dao.MaterialDao;
import com.lqs.dataservice.entity.Material;
import com.nip.db.mongodb.utils.tips.Response;
import com.nip.db.mongodb.utils.tips.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ArmyService
 *
 * @author < a href=" ">BBB</ a>
 * @version v1.0.01
 * @date 2019-12-27 14:41
 */
@Service
public class MaterialService {
  @Autowired
  MaterialDao materialDao;

  public List<Material> findAllMaterial() {
    return materialDao.findAll();
  }

  public Material findMaterialById(String id) {
    return materialDao.findById(id).orElse(null);
  }
  public List<Material> findAllByMatParengId(String id) {
    return materialDao.findAllByMatParengId(id);
  }

  public Response saveMaterial(Material entity) {
    try {

      materialDao.save(entity);
      return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
    } catch (Exception e) {
      return new Response(ResponseCode.CODE_202, e.getMessage());
    }
  }

  public Response deleteMaterialById(String id) {
    try {
      materialDao.deleteById(id);
      return new Response(ResponseCode.CODE_200, MessageConstants.SUCCESS);
    } catch (Exception e) {
      return new Response(ResponseCode.CODE_202, e.getMessage());
    }
  }
}
